package com;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBtools {	
	public static Connection getConnection() throws SQLException, ClassNotFoundException {
		Class.forName("org.mariadb.jdbc.Driver");
		String url = "jdbc:mariadb://localhost:3306/epidemicmanagement";
		Connection conn = DriverManager.getConnection(url,"root","123456");
		Statement stmt = conn.createStatement();
		return conn;
	}
	//查询select
	public static ResultSet query(String sql) throws ClassNotFoundException,SQLException {
		Connection conn = getConnection();
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		return rs;
	}
	//修改数据insert update delete
	public static int execute(String sql) throws ClassNotFoundException,SQLException {
	Connection conn = getConnection();
	Statement stmt = conn. createStatement();
	System.out.println("in DBTools.execute() sql=" + sql);
	int r = stmt.executeUpdate(sql);
	stmt.close();
	conn.close();
	return r;
	}

}
